//
//  YFBaseViewController.m
//  CoollangTennisBall
//
//  Created by Coollang on 2017/9/12.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "YFBaseViewController.h"

@interface YFBaseViewController ()

@end

@implementation YFBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - 系统自带弹框
- (UIAlertController *)showAlertControllerTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle defalutTitle:(NSString *)defaultTitle cancelAction:(void(^)(UIAlertAction *action))cancelAction defalutAction:(void(^)(UIAlertAction *action))defalutAction {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    
    cancelTitle = cancelTitle.length > 0 ? cancelTitle:@"确定";
    UIAlertAction *cancelItem = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        if (cancelAction) {
            cancelAction(action);
        }
    }];
    [alertController addAction:cancelItem];
    
    
    if (defaultTitle.length > 0) {
        UIAlertAction *defalut = [UIAlertAction actionWithTitle:defaultTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (defalutAction) {
                defalutAction(action);
            }
        }];
        [alertController addAction:defalut];
    }
    
    if ((cancelTitle.length + defaultTitle.length) <= 0) {
        UIAlertAction *cancelItem = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (cancelAction) {
                cancelAction(action);
            }
        }];
        [alertController addAction:cancelItem];
    }
    [self presentViewController:alertController animated:YES completion:nil];
    return alertController;
}



@end
